package user

import (
	"chaowan/data_source"
	"chaowan/models"
	"chaowan/service"
	"context"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/go-pay/gopay"
	"github.com/go-pay/gopay/wechat"
	"math/rand"
	"net/http"
	"strconv"
	"strings"
	"time"
)

var (
	mchID  string = "1696050885"                       // 商户号
	apiKey string = "shanyuapp12345678912345678912345" //
	pturl         = "https://api.xingjichaowan.vip"
)

type PayBody struct {
	Orderid int64 `json:"orderid" from:"orderid"`
}

func generateRandomInt() int {
	// 设置随机种子以确保每次运行结果不同
	rand.Seed(time.Now().UnixNano())

	// 生成 [0, 9) 范围内的随机整数
	randomInt := rand.Intn(9)

	// 调整到 [1, 9] 范围内
	adjustedRandomInt := randomInt + 1

	return adjustedRandomInt
}
func BuydaibialiWechat(ctx *gin.Context) {
	request := BuydaibiBody{}
	ctx.ShouldBind(&request)
	uid := request.Uid
	qudao := request.Qudao
	packageid := request.Packageid
	if uid == 0 {
		ctx.JSON(http.StatusOK, gin.H{
			"code":    101,
			"error":   1,
			"success": 400,
			"data":    "on",
			"msg":     "请登录",
		})
		return
	}
	var packageinfo models.Package
	data_source.Db.Where("id = ?", packageid).First(&packageinfo)
	if packageinfo.Num > 0 {
		var buydaibis []models.Buydaibi
		data_source.Db.Where("uid = ?", uid).Where("status = 2").Where("packageid = ?", buydaibis).Find(&buydaibis)
		if len(buydaibis) >= int(packageinfo.Num) {
			ctx.JSON(http.StatusOK, gin.H{
				"code":    101,
				"error":   1,
				"success": 400,
				"data":    "on",
				"msg":     "购买次数已经用完",
			})
			return
		}
	}

	orderno := Generateto(time.Time{})

	lijian := generateRandomInt()
	money2 := int(packageinfo.Price*100) - lijian
	if uid == 21525 {
		money2 = 1
	}
	buy := models.Buydaibi{
		Uid:       uid,
		Packageid: packageid,
		Addtime:   time.Now().Unix(),
		Status:    1,
		Orderno:   orderno,
		Qudao:     qudao,
		Pricepay:  int64(money2),
	}
	data_source.Db.Create(&buy)

	var user models.User
	data_source.Db.Where("id = ?", uid).First(&user)

	client := wechat.NewClient(appID, mchID, apiKey, true)
	client.SetCountry(wechat.China)
	client.AddCertPemFilePath("upload/apiclient_cert.pem", "upload/apiclient_key.pem")

	//money2 := 1
	//初始化参数Map
	bm := make(gopay.BodyMap)
	//OrderNo := util.RandomString(32)

	bm.Set("nonce_str", Generateto(time.Time{})).
		Set("body", "充值矿石").
		Set("out_trade_no", orderno).
		Set("total_fee", money2).
		Set("spbill_create_ip", ctx.ClientIP()).
		Set("notify_url", pturl+"/user/wechatNotifydaibi").
		Set("trade_type", wechat.TradeType_JsApi).
		Set("sign_type", wechat.SignType_MD5).
		Set("openid", user.RoutineOpenid)

	//请求支付下单，成功后得到结果
	wxRsp, err := client.UnifiedOrder(ctx, bm)
	fmt.Println(wxRsp)
	timeStamp := strconv.FormatInt(time.Now().Unix(), 10)
	packages := "prepay_id=" + wxRsp.PrepayId // 此处的 wxRsp.PrepayId ,统一下单成功后得到
	paySign := ""
	paySign = wechat.GetJsapiPaySign(appID, wxRsp.NonceStr, packages, wechat.SignType_MD5, timeStamp, apiKey)
	//fmt.Println(paySign)
	//return
	data := map[string]interface{}{
		"appId":     wxRsp.Appid,
		"timeStamp": timeStamp,
		"nonceStr":  wxRsp.NonceStr,
		"package":   packages,
		"signType":  wechat.SignType_MD5,
		"sign":      paySign,
		"order_no":  orderno, // 订单号
	}

	if err != nil {
		ctx.JSON(http.StatusOK, gin.H{
			"code": -1,
			"msg":  "稍后再试",
			"data": gin.H{},
		})
		return
	}
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"msg":     "ok",
		"error":   0,
		"success": 200,
		"data":    data,
	})
	return

}

// @Summary 微信支付回调
// @Produce  json
// @Success 200 {string} string "success"
// @Router /v1/wechat_notify [post]
func WechatNotifydaibi(c *gin.Context) {
	notifyRsp, err := wechat.ParseNotifyToBodyMap(c.Request)
	//fmt.Println(notifyRsp)
	if err != nil {
		c.String(200, "error")
		return
	}
	ok, errSign := wechat.VerifySign(apiKey, wechat.SignType_MD5, notifyRsp)
	if ok { // 验证成功
		fmt.Println("errSign = ", errSign)
		Zhifupaydaibi(notifyRsp["out_trade_no"].(string))
		c.String(200, "success")
		return
	}
	c.String(200, "error")
	return
}

// 支付完成
func Zhifupaydaibi(order string) {
	var orders models.Buydaibi
	data_source.Db.Where("orderno = ?", order).First(&orders)
	data_source.Db.Model(&models.Buydaibi{}).Where("orderno = ?", order).Update("status", 2)

	var packageinfo models.Package
	data_source.Db.Where("id = ?", orders.Packageid).First(&packageinfo)

	var user models.User
	data_source.Db.Where("id = ?", orders.Uid).First(&user)

	userupdata := models.User{
		Daibi: user.Daibi + packageinfo.Daibi,
		Zhifu: user.Zhifu + packageinfo.Price,
	}
	data_source.Db.Where("id = ?", orders.Uid).Updates(&userupdata)

	userdaibi := models.Userdaibi{
		Uid:     orders.Uid,
		Status:  1,
		Addtime: time.Now().Unix(),
		Daibi:   packageinfo.Daibi,
		Title:   "小程序充值",
		State:   1,
		Sydaibi: user.Daibi + packageinfo.Daibi,
	}
	data_source.Db.Create(&userdaibi)

	userchongzhi := models.Userchongzhi{
		Uid:      orders.Uid,
		Addtime:  time.Now().Unix(),
		Price:    packageinfo.Price,
		State:    1,
		Paystate: 3,
		Qudao:    "weixin",
	}
	data_source.Db.Create(&userchongzhi)

	if user.ClickId != "" {
		Payshangbao(user, int(orders.Pricepay))
	}
}

// 微信支付
func Wechatpayxcxgood(orderno string, price float64, user models.User, ip string, orderid int64) (dataval map[string]interface{}) {
	ctx := context.Background()

	client := wechat.NewClient(appID, mchID, apiKey, true)
	client.SetCountry(wechat.China)
	client.AddCertPemFilePath("upload/apiclient_cert.pem", "upload/apiclient_key.pem")
	lijian := generateRandomInt()
	money2 := int(price*100) - lijian
	//money2 := 1
	//初始化参数Map
	bm := make(gopay.BodyMap)
	//OrderNo := util.RandomString(32)
	if user.ID == 21525 {
		money2 = 1
	}
	data_source.Db.Model(models.Ordergood{}).Where("orderno = ?", orderno).Update("pricepay", money2)
	bm.Set("nonce_str", Generateto(time.Time{})).
		Set("body", "商品购买").
		Set("out_trade_no", orderno).
		Set("total_fee", money2).
		Set("spbill_create_ip", ip).
		Set("notify_url", pturl+"/user/wechatNotify").
		Set("trade_type", wechat.TradeType_JsApi).
		Set("sign_type", wechat.SignType_MD5).
		Set("openid", user.RoutineOpenid)

	//请求支付下单，成功后得到结果
	wxRsp, err := client.UnifiedOrder(ctx, bm)
	//fmt.Println(wxRsp)
	if err != nil {
		fmt.Println(err)
	}

	timeStamp := strconv.FormatInt(time.Now().Unix(), 10)
	packages := "prepay_id=" + wxRsp.PrepayId // 此处的 wxRsp.PrepayId ,统一下单成功后得到
	paySign := ""
	paySign = wechat.GetJsapiPaySign(appID, wxRsp.NonceStr, packages, wechat.SignType_MD5, timeStamp, apiKey)
	//fmt.Println(paySign)
	//return
	data := map[string]interface{}{
		"appId":     wxRsp.Appid,
		"timeStamp": timeStamp,
		"nonceStr":  wxRsp.NonceStr,
		"package":   packages,
		"signType":  wechat.SignType_MD5,
		"sign":      paySign,
		"order_no":  orderno, // 订单号
		"orderid":   orderid,
	}

	return data
}

// @Summary 微信支付回调
// @Produce  json
// @Success 200 {string} string "success"
// @Router /v1/wechat_notify [post]
func WechatNotify(c *gin.Context) {
	notifyRsp, err := wechat.ParseNotifyToBodyMap(c.Request)
	//fmt.Println(notifyRsp)
	if err != nil {
		c.String(200, "error")
		return
	}
	ok, errSign := wechat.VerifySign(apiKey, wechat.SignType_MD5, notifyRsp)
	if ok { // 验证成功
		fmt.Println("errSign = ", errSign)
		Zhifupaygood(notifyRsp["out_trade_no"].(string))
		c.String(200, "success")
		return
	}
	c.String(200, "error")
	return
}

// 支付完成
func Zhifupaygood(order string) {
	var orders models.Ordergood
	data_source.Db.Where("order_no = ?", order).First(&orders)
	data_source.Db.Model(&models.Ordergood{}).Where("order_no = ?", order).Update("status", 2)

	now := time.Now()
	zeroToday := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Unix()

	//startOfToday := time.Now().Truncate(24 * time.Hour)
	startTimestamp := getTodayMidnightTimestamp()
	var address models.Address
	data_source.Db.Where("id = ?", orders.Addressid).First(&address)
	usergoodarea := models.Usergoodarea{
		Uid:       orders.Uid,
		Addressid: orders.Addressid,
		Phone:     address.Phone,
		Name:      address.Name,
		Province:  address.Province,
		City:      address.City,
		County:    address.County,
		Area:      address.Area,
		Addtime:   zeroToday,
		Kdstatus:  1,
	}
	data_source.Db.Create(&usergoodarea)

	var user models.User
	data_source.Db.Where("id = ?", orders.Uid).First(&user)
	UploadShippingInfo(order, user)
	var good models.Goods
	data_source.Db.Where("id = ?", orders.Goodid).First(&good)

	for i := 0; i < int(orders.Num); i++ {
		service.Gooduser(user, good, 1, 1, 2, usergoodarea.ID, orders.ID)
	}

	var userdayprice models.Userdayprice
	data_source.Db.Where("uid = ?", orders.Uid).Where("addtime = ?", startTimestamp).First(&userdayprice)
	if userdayprice.ID == 0 {
		userdaypriceadd := models.Userdayprice{
			Uid:     orders.Uid,
			Addtime: startTimestamp,
			Price:   good.Price * float64(orders.Num),
		}
		data_source.Db.Create(&userdaypriceadd)
	} else {
		data_source.Db.Model(&models.Userdayprice{}).Where("id = ?", userdayprice.ID).Update("price", userdayprice.Price+good.Price*float64(orders.Num))
	}

	userorder := models.Userorder{
		Uid:       orders.Uid,
		Addtime:   time.Now().Unix(),
		State:     1,
		Paystatus: 5,
		Price:     good.Price * float64(orders.Num),
		Orderid:   orders.ID,
	}
	data_source.Db.Create(&userorder)

	userchongzhi := models.Userchongzhi{
		Uid:      orders.Uid,
		Addtime:  time.Now().Unix(),
		Price:    good.Price * float64(orders.Num),
		State:    4,
		Paystate: 3,
		Qudao:    "weixin",
	}
	data_source.Db.Create(&userchongzhi)
	if user.ClickId != "" {
		Payshangbao(user, int(orders.Pricepay))
	}
}

// 微信支付一番赏
func Wechatpayxcxyfs(orderno string, price float64, user models.User, ip string, orderid int64) (dataval map[string]interface{}) {
	ctx := context.Background()

	client := wechat.NewClient(appID, mchID, apiKey, true)
	client.SetCountry(wechat.China)
	client.AddCertPemFilePath("upload/apiclient_cert.pem", "upload/apiclient_key.pem")
	lijian := generateRandomInt()
	money2 := int(price*100) - lijian
	//money2 := 1
	//初始化参数Map
	bm := make(gopay.BodyMap)
	//OrderNo := util.RandomString(32)
	if user.ID == 21525 {
		money2 = 1
	}
	data_source.Db.Model(&models.Orderfanshang{}).Where("orderno = ?", orderno).Update("pricepay", money2)
	bm.Set("nonce_str", Generateto(time.Time{})).
		Set("body", "购买一番赏").
		Set("out_trade_no", orderno).
		Set("total_fee", money2).
		Set("spbill_create_ip", ip).
		Set("notify_url", pturl+"/user/wechatNotifyyfs").
		Set("trade_type", wechat.TradeType_JsApi).
		Set("sign_type", wechat.SignType_MD5).
		Set("openid", user.RoutineOpenid)

	//请求支付下单，成功后得到结果
	wxRsp, err := client.UnifiedOrder(ctx, bm)
	if err != nil {
		fmt.Println(err)
	}

	timeStamp := strconv.FormatInt(time.Now().Unix(), 10)
	packages := "prepay_id=" + wxRsp.PrepayId // 此处的 wxRsp.PrepayId ,统一下单成功后得到
	paySign := ""
	paySign = wechat.GetJsapiPaySign(appID, wxRsp.NonceStr, packages, wechat.SignType_MD5, timeStamp, apiKey)
	//fmt.Println(paySign)
	//return
	data := map[string]interface{}{
		"appId":     wxRsp.Appid,
		"timeStamp": timeStamp,
		"nonceStr":  wxRsp.NonceStr,
		"package":   packages,
		"signType":  wechat.SignType_MD5,
		"sign":      paySign,
		"order_no":  orderno, // 订单号
		"orderid":   orderid, // 订单号
	}

	return data
}

// @Summary 微信支付回调
// @Produce  json
// @Success 200 {string} string "success"
// @Router /v1/wechat_notify [post]
func WechatNotifyyfs(c *gin.Context) {
	notifyRsp, err := wechat.ParseNotifyToBodyMap(c.Request)
	//fmt.Println(notifyRsp)
	if err != nil {
		c.String(200, "error")
		return
	}
	ok, errSign := wechat.VerifySign(apiKey, wechat.SignType_MD5, notifyRsp)
	if ok { // 验证成功
		fmt.Println("errSign = ", errSign)
		Zhifupayyfs(notifyRsp["out_trade_no"].(string))
		c.String(200, "success")
		return
	}
	c.String(200, "error")
	return
}

// 支付完成
func Zhifupayyfs(order string) {
	var orders models.Orderfanshang
	data_source.Db.Where("orderno = ?", order).First(&orders)
	data_source.Db.Model(&models.Orderfanshang{}).Where("orderno = ?", order).Update("status", 2)

	//startOfToday := time.Now().Truncate(24 * time.Hour)
	startTimestamp := getTodayMidnightTimestamp()
	var userdayprice models.Userdayprice
	data_source.Db.Where("uid = ?", orders.Uid).Where("addtime = ?", startTimestamp).First(&userdayprice)
	if userdayprice.ID == 0 {
		userdaypriceadd := models.Userdayprice{
			Uid:     orders.Uid,
			Addtime: startTimestamp,
			Price:   orders.Price,
		}
		data_source.Db.Create(&userdaypriceadd)
	} else {
		data_source.Db.Model(&models.Userdayprice{}).Where("id = ?", userdayprice.ID).Update("price", userdayprice.Price+orders.Price)
	}

	userorder := models.Userorder{
		Uid:       orders.Uid,
		Addtime:   time.Now().Unix(),
		State:     3,
		Paystatus: 5,
		Price:     orders.Price,
		Orderid:   orders.ID,
	}
	data_source.Db.Create(&userorder)
	//fmt.Println(orderadd)

	Zhongjiangfs(orders)
	var user models.User
	data_source.Db.Where("id = ?", orders.Uid).First(&user)
	//判断是否升级vip
	service.Vipsj(user, orders.Price)
	UploadShippingInfo(order, user)

	userchongzhi := models.Userchongzhi{
		Uid:      orders.Uid,
		Addtime:  time.Now().Unix(),
		Price:    orders.Price,
		State:    3,
		Paystate: 3,
		Qudao:    "weixin",
	}
	data_source.Db.Create(&userchongzhi)
	if user.ClickId != "" {
		Payshangbao(user, int(orders.Pricepay))
	}
}

// 微信支付一扭蛋机
func Wechatpayxcxndj(orderno string, price float64, user models.User, ip string, orderid int64) (dataval map[string]interface{}) {
	ctx := context.Background()

	client := wechat.NewClient(appID, mchID, apiKey, true)
	client.SetCountry(wechat.China)
	client.AddCertPemFilePath("upload/apiclient_cert.pem", "upload/apiclient_key.pem")
	lijian := generateRandomInt()
	money2 := int(price*100) - lijian
	//money2 := 1
	//初始化参数Map
	bm := make(gopay.BodyMap)
	//OrderNo := util.RandomString(32)
	if user.ID == 21525 {
		money2 = 1
	}
	data_source.Db.Model(&models.Orderniudan{}).Where("orderno = ?", orderno).Update("pricepay", money2)
	bm.Set("nonce_str", Generateto(time.Time{})).
		Set("body", "商品购买").
		Set("out_trade_no", orderno).
		Set("total_fee", money2).
		Set("spbill_create_ip", ip).
		Set("notify_url", pturl+"/user/wechatNotifyndj").
		Set("trade_type", wechat.TradeType_JsApi).
		Set("sign_type", wechat.SignType_MD5).
		Set("openid", user.RoutineOpenid)

	//请求支付下单，成功后得到结果
	wxRsp, err := client.UnifiedOrder(ctx, bm)
	if err != nil {
		fmt.Println(err)
	}

	timeStamp := strconv.FormatInt(time.Now().Unix(), 10)
	packages := "prepay_id=" + wxRsp.PrepayId // 此处的 wxRsp.PrepayId ,统一下单成功后得到
	paySign := ""
	paySign = wechat.GetJsapiPaySign(appID, wxRsp.NonceStr, packages, wechat.SignType_MD5, timeStamp, apiKey)
	//fmt.Println(paySign)
	//return
	data := map[string]interface{}{
		"appId":     wxRsp.Appid,
		"timeStamp": timeStamp,
		"nonceStr":  wxRsp.NonceStr,
		"package":   packages,
		"signType":  wechat.SignType_MD5,
		"sign":      paySign,
		"order_no":  orderno, // 订单号
		"orderid":   orderid, // 订单号
	}

	return data
}

// @Summary 微信支付回调
// @Produce  json
// @Success 200 {string} string "success"
// @Router /v1/wechat_notify [post]
func WechatNotifyndj(c *gin.Context) {
	notifyRsp, err := wechat.ParseNotifyToBodyMap(c.Request)
	//fmt.Println(notifyRsp)
	if err != nil {
		c.String(200, "error")
		return
	}
	ok, errSign := wechat.VerifySign(apiKey, wechat.SignType_MD5, notifyRsp)
	if ok { // 验证成功
		fmt.Println("errSign = ", errSign)
		Zhifupayndj(notifyRsp["out_trade_no"].(string))
		c.String(200, "success")
		return
	}
	c.String(200, "error")
	return
}

// 支付完成
func Zhifupayndj(order string) {
	var orders models.Orderniudan
	data_source.Db.Where("orderno = ?", order).First(&orders)
	data_source.Db.Model(&models.Orderniudan{}).Where("orderno = ?", order).Update("status", 2)

	//startOfToday := time.Now().Truncate(24 * time.Hour)
	startTimestamp := getTodayMidnightTimestamp()
	var userdayprice models.Userdayprice
	data_source.Db.Where("uid = ?", orders.Uid).Where("addtime = ?", startTimestamp).First(&userdayprice)
	if userdayprice.ID == 0 {
		userdaypriceadd := models.Userdayprice{
			Uid:     orders.Uid,
			Addtime: startTimestamp,
			Price:   orders.Price,
		}
		data_source.Db.Create(&userdaypriceadd)
	} else {
		data_source.Db.Model(&models.Userdayprice{}).Where("id = ?", userdayprice.ID).Update("price", userdayprice.Price+orders.Price)
	}

	userorder := models.Userorder{
		Uid:       orders.Uid,
		Addtime:   time.Now().Unix(),
		State:     2,
		Paystatus: 5,
		Price:     orders.Price,
		Orderid:   orders.ID,
	}
	data_source.Db.Create(&userorder)
	//fmt.Println(orderadd)

	Zhongjiangnd(orders)
	var user models.User
	data_source.Db.Where("id = ?", orders.Uid).First(&user)
	//判断是否升级vip
	service.Vipsj(user, orders.Price)
	UploadShippingInfo(order, user)

	userchongzhi := models.Userchongzhi{
		Uid:      orders.Uid,
		Addtime:  time.Now().Unix(),
		Price:    orders.Price,
		State:    2,
		Paystate: 3,
		Qudao:    "weixin",
	}
	data_source.Db.Create(&userchongzhi)
	if user.ClickId != "" {
		Payshangbao(user, int(orders.Pricepay))
	}
}

// 微信支付一邮费
func Wechatpayxcxyoufei(orderno string, price float64, user models.User, ip string) (dataval map[string]interface{}) {
	ctx := context.Background()
	client := wechat.NewClient(appID, mchID, apiKey, true)
	client.SetCountry(wechat.China)
	client.AddCertPemFilePath("upload/apiclient_cert.pem", "upload/apiclient_key.pem")
	lijian := generateRandomInt()
	money2 := int(price*100) - lijian
	//money2 := 1
	//初始化参数Map
	bm := make(gopay.BodyMap)
	//OrderNo := util.RandomString(32)
	if user.ID == 21525 {
		money2 = 1
	}
	data_source.Db.Model(&models.Usergoodarea{}).Where("orderno = ?", orderno).Update("pricepay", money2)
	bm.Set("nonce_str", Generateto(time.Time{})).
		Set("body", "补充邮费").
		Set("out_trade_no", orderno).
		Set("total_fee", money2).
		Set("spbill_create_ip", ip).
		Set("notify_url", pturl+"/user/wechatNotifyyf").
		Set("trade_type", wechat.TradeType_JsApi).
		Set("sign_type", wechat.SignType_MD5).
		Set("openid", user.RoutineOpenid)

	//请求支付下单，成功后得到结果
	wxRsp, err := client.UnifiedOrder(ctx, bm)
	if err != nil {
		fmt.Println(err)
	}

	timeStamp := strconv.FormatInt(time.Now().Unix(), 10)
	packages := "prepay_id=" + wxRsp.PrepayId // 此处的 wxRsp.PrepayId ,统一下单成功后得到
	paySign := ""
	paySign = wechat.GetJsapiPaySign(appID, wxRsp.NonceStr, packages, wechat.SignType_MD5, timeStamp, apiKey)
	//fmt.Println(paySign)
	//return
	data := map[string]interface{}{
		"appId":     wxRsp.Appid,
		"timeStamp": timeStamp,
		"nonceStr":  wxRsp.NonceStr,
		"package":   packages,
		"signType":  wechat.SignType_MD5,
		"sign":      paySign,
		"order_no":  orderno, // 订单号
	}

	return data
}

// @Summary 微信支付回调
// @Produce  json
// @Success 200 {string} string "success"
// @Router /v1/wechat_notify [post]
func WechatNotifyyf(c *gin.Context) {
	notifyRsp, err := wechat.ParseNotifyToBodyMap(c.Request)
	//fmt.Println(notifyRsp)
	if err != nil {
		c.String(200, "error")
		return
	}
	ok, errSign := wechat.VerifySign(apiKey, wechat.SignType_MD5, notifyRsp)
	if ok { // 验证成功
		fmt.Println("errSign = ", errSign)
		Zhifupayyf(notifyRsp["out_trade_no"].(string))
		c.String(200, "success")
		return
	}
	c.String(200, "error")
	return
}

// 支付完成
func Zhifupayyf(order string) {
	var orders models.Usergoodarea
	data_source.Db.Where("orderno = ?", order).First(&orders)
	data_source.Db.Model(&models.Usergoodarea{}).Where("orderno = ?", order).Update("kdstatus", 1)

	goodidarr := strings.Split(orders.Goodids, ",")
	usergoodupdate := models.Usergood{
		Usergoodareaid: orders.ID,
		Shouhuo:        3,
		Status:         2,
		Updatetime:     time.Now().Unix(),
	}
	data_source.Db.Where("id in (?)", goodidarr).Updates(&usergoodupdate)

	userchongzhi := models.Userchongzhi{
		Uid:      orders.Uid,
		Addtime:  time.Now().Unix(),
		Price:    15,
		State:    5,
		Paystate: 3,
		Qudao:    "weixin",
	}
	data_source.Db.Create(&userchongzhi)

	var user models.User
	data_source.Db.Where("id = ?", orders.Uid).First(&user)
	if user.ClickId != "" {
		Payshangbao(user, int(orders.Pricepay))
	}

}
